﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace DusonFramework.Core.Web
{
    public class MediaHelper
    {
        static public string ShowPlayer(string FlvSource)
        {
            if (FlvSource.ToLower().IndexOf(".swf") > -1 || FlvSource.ToLower().IndexOf(".flv") > -1)
            {
                return Player(FlvSource);
            }
            else
            {
                string flvid = string.Empty;
                if (FlvSource.IndexOf("v.youku.com") > -1)
                {
                    flvid = Regex.Match(FlvSource, @"\/id_(?<content>[^\/]*?)\.html$", RegexOptions.Compiled | RegexOptions.IgnoreCase).Groups["content"].Value;
                    return Player("http://player.youku.com/player.php/sid/" + flvid + "/v.swf");
                }
                else if (FlvSource.IndexOf("tudou.com") > -1)
                {
                    flvid = Regex.Match(FlvSource, @"\/(?<content>[^\/]*?)\/$", RegexOptions.Compiled | RegexOptions.IgnoreCase).Groups["content"].Value;
                    return Player("http://www.tudou.com/v/" + flvid + "");
                }
                else if (FlvSource.IndexOf("v.ku6.com") > -1)
                {
                    flvid = Regex.Match(FlvSource, @"\/(?<content>[^\/]*?)\.html$", RegexOptions.Compiled | RegexOptions.IgnoreCase).Groups["content"].Value;
                    return Player("http://player.ku6.com/refer/" + flvid + "/v.swf");
                }
            }
            return string.Empty;
        }

        static public string Player(string FlvSource)
        {
            string listSTR = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"225\" height=\"200\">";
            listSTR += "<param name=\"movie\" value=\"" + FlvSource + "\" />";
            listSTR += "<param name=\"quality\" value=\"high\" />";
            listSTR += "<param name=\"allowFullScreen\" value=\"true\" />";
            listSTR += "<embed src=\"" + FlvSource + "\" allowfullscreen=\"true\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"225\" height=\"200\"></embed>";
            listSTR += "</object>";
            return listSTR;
        }

    }
}
